package mianshi_1;

import java.io.IOException;
import java.util.Properties;

/**
 * 适合复杂实例化	
 * 静态代码块去实例化对象
 * 处理复杂的情况
 * @author Administrator
 *
 */
public class Java_02_Singleton_staticBlock_03 {
	
	public static final Java_02_Singleton_staticBlock_03 INSTANCE;
	
	public String info;
	
	/**
	 * 静态代码块实例化对象
	 */
	static {
		try {
			//加载配置文件
			Properties properties = new Properties();
			//在类加载的时候读取配置文件
			properties.load(Java_02_Singleton_staticBlock_03.class.getClassLoader().getResourceAsStream("Singleton.properties"));
			
			INSTANCE = new Java_02_Singleton_staticBlock_03(properties.getProperty("info"));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		
	}
	
	private Java_02_Singleton_staticBlock_03(String info) {
		this.info = info;
	}
	
	@Override
	public String toString() {
		return "Java_02_Singleton_staticBlock_03 [info=" + info + "]";
	}

	//测试
	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public static void main(String[] args) {
		Java_02_Singleton_staticBlock_03 ins = Java_02_Singleton_staticBlock_03.INSTANCE;
		System.out.println(ins);
	}

}
